<?php
namespace Common\Model;
use Common\Model\BaseModel;
class FireModel extends BaseModel
{
    protected $tableName = 'fire';
    
    public function addFire($post)
    {
    	$ret = array('status'=>'','info'=>'');
    	$data = $this->returnData($post);

    	if($this->create($data))
        {
    		$res = null !== $data['id'] ? $this->save($data) : $this->add($data);
    		if(false !== $res)
            {
    			$ret['status'] = true;
    			$ret['info']   = "Success";
    		}
            else
            {
    			$ret['status'] = false;
    			$ret['info']   = $this->getDbError();
    		}
    	}
        else
        {
    			$ret['status'] = false;
    			$ret['info']   = $this->getError();
    	}
    
    	return $ret;
    }
    public function returnData($post)
    {
    	$return['id'] 				   = !empty($post['id']) ? intval($post['id']) : null;
    	$return['tab_fire_id'] 		   = !empty($post['tab_fire_id']) ? addslashes($post['tab_fire_id']) : $this->createTabFireid();
    	$return['apply_time'] 		   = !empty($post['apply_time']) ? date('Y-m-d H:i:s',$post['apply_time']) : date('Y-m-d H:i:s');
    	$return['status'] 			   = !empty($post['status']) ? intval($post['status']) : 1;
    	$return['remark'] 			   = !empty($post['remark']) ? addslashes($post['remark']) : '';
    	$return['staff_id'] 		   = !empty($post['staff_id']) ? intval($post['staff_id']) : $this->staff_id;
        $return['apply_unit']          = !empty($post['apply_unit']) ? addslashes($post['apply_unit']) : '';
        $return['apply_content']       = !empty($post['apply_content']) ? addslashes($post['apply_content']) : '';
        $return['powder_amount']       = !empty($post['powder_amount']) ? intval($post['powder_amount']) : 0;
        $return['powder_location']     = !empty($post['powder_location']) ? addslashes($post['powder_location']) : '';
        $return['powder_configure']    = !empty($post['powder_configure']) ? date('Y-m-d H:i:s',strtotime($post['powder_configure'])) : date('Y-m-d H:i:s');
        $return['powder_repair']       = !empty($post['powder_repair']) ? date('Y-m-d H:i:s',strtotime($post['powder_repair'])): date('Y-m-d H:i:s');
        $return['carbon_amount']       = !empty($post['carbon_amount']) ? intval($post['carbon_amount']) : 0;
        $return['carbon_location']     = !empty($post['carbon_location']) ? addslashes($post['carbon_location']) : '';
        $return['carbon_configure']    = !empty($post['carbon_configure']) ? date('Y-m-d H:i:s',strtotime($post['carbon_configure'])): date('Y-m-d H:i:s');
        $return['carbon_repair']       = !empty($post['carbon_repair']) ? date('Y-m-d H:i:s',strtotime($post['carbon_repair'])): date('Y-m-d H:i:s');
        $return['blanket_amount']      = !empty($post['blanket_amount']) ? intval($post['blanket_amount']) : 0;
        $return['blanket_location']    = !empty($post['blanket_location']) ? addslashes($post['blanket_location']) : '';
        $return['blanket_configure']   = !empty($post['blanket_configure']) ? date('Y-m-d H:i:s',strtotime($post['blanket_configure'])): date('Y-m-d H:i:s');
        $return['extinguisher_amount'] = !empty($post['extinguisher_amount']) ? intval($post['extinguisher_amount']) : 0;
        $return['extinguisher_location']= !empty($post['extinguisher_location']) ? addslashes($post['extinguisher_location']) : '';
        $return['extinguisher_cofigure']= !empty($post['extinguisher_cofigure']) ? date('Y-m-d H:i:s',strtotime($post['extinguisher_cofigure'])) : date('Y-m-d H:i:s');
        $return['is_drift']             = !empty($post['is_drift']) ? $post['is_drift'] : 1;
        $return['is_apply']             = !empty($post['is_apply']) ? $post['is_apply'] : $this->returnApply();
 		return $return;
    }

    public function createTabFireid()
    {
    	$tab_fire_id = date('YmdHis',time());
    	return $tab_fire_id;
    }


    public function getList()
    {
      $list = $this->select();
      return $list;
    }
    public function returnApply(){
        if($this->role_id == self::ROLE_TEACHER){
            return 1;
        }else{
            return 2;
        }
    }

}